package recursion;

import java.util.Scanner;

public class HanoiTower {
    public static void main(String[] args) {
        while (true) {
            System.out.print("玩几层汉诺塔：");
            int n = new Scanner(System.in).nextInt();
            f(n, "from", "middle", "to");
        }
    }

//    private static void f(int n) {
//        f(n, "A", "B", "C");
//    }
//
//    private static void f(int n, String from, String mid, String to) {
//        if (n == 1) {
//            System.out.println(from + "-->" + to);
//        } else {
////            f(n - 1, from, to, mid);
////            System.out.println(from+"-->"+mid);
////            f(n - 1, mid, from, to);
//            f(n - 1, from, to, mid);
//            f(1, from, mid, to);
//            f(n - 1, mid, from, to);
//        }
//    }

    public static void f(int n, String from, String middle, String to) {
        if (n == 1) {
            System.out.println(from + "-->" + to);
            return;
        }
        f(n - 1, from, to, middle);
        f(1, from, middle, to);
        f(n - 1, middle, from, to);
    }
}


